﻿using System;
using Sizebox.CharacterEditor;
using UnityEngine;

// Token: 0x020001BF RID: 447
[RequireComponent(typeof(Animator))]
public class ComplexMicroLookAtController : MicroLookAtController
{
	// Token: 0x0600091A RID: 2330 RVA: 0x00055088 File Offset: 0x00053288
	protected override void Awake()
	{
		base.Awake();
		GameObject gameObject = new GameObject();
		gameObject.AddComponent<NotABone>();
		this.assistReference = gameObject.transform;
		this.assistReference.position = this.head.position + base.transform.forward;
		this.assistReference.parent = this.head;
		base.enabled = false;
	}

	// Token: 0x0600091B RID: 2331 RVA: 0x000550F4 File Offset: 0x000532F4
	protected override void LateUpdate()
	{
		if (this.active && this.targetEntity == null)
		{
			this.active = false;
		}
		if (this.active)
		{
			float f = Vector3.Angle(base.transform.forward, base.target - this.head.position);
			if (Mathf.Abs(f) < 85f)
			{
				Vector3 fromDirection = this.assistReference.position - this.head.position;
				Vector3 toDirection = base.target - this.head.position;
				Quaternion b = Quaternion.FromToRotation(fromDirection, toDirection) * this.head.rotation;
				this.head.rotation = Quaternion.Slerp(this.prevRot, b, Time.deltaTime * 3f);
			}
			else
			{
				this.head.rotation = Quaternion.Slerp(this.prevRot, this.head.rotation, Time.deltaTime * 3f);
			}
			this.prevRot = this.head.rotation;
		}
		else if (Quaternion.Angle(this.prevRot, this.head.rotation) > 3f)
		{
			this.head.rotation = Quaternion.Slerp(this.prevRot, this.head.rotation, Time.deltaTime * 3f);
			this.prevRot = this.head.rotation;
		}
		else
		{
			base.enabled = false;
		}
	}

	// Token: 0x0600091C RID: 2332 RVA: 0x00055283 File Offset: 0x00053483
	private void OnDestroy()
	{
		if (this.assistReference != null)
		{
			UnityEngine.Object.Destroy(this.assistReference.gameObject);
		}
	}

	// Token: 0x04000EE4 RID: 3812
	private Transform assistReference;
}
